package trader.db;
import trader.*;

public class BrokerDAOImplTest {
    
    public static void main(String args[])  {
        
        System.out.println("BrokerDAOImplTest.main: testing BrokerDAOImpl");
        
        BrokerDAOImpl db = null;
        Customer customer = null;
        
        try {
            db = new BrokerDAOImpl();
        } catch (Exception e) {
            System.out.println(e);
        }
        
        try {
            // testing retrieving all customers
            System.out.println("BrokerDAOImplTest.main: retrieving all Customers");
            Customer [] allCustomers = db.getAllCustomers();
            System.out.println("BrokerDAOImplTest.main: printing all Customers");
            for (int i = 0; i < allCustomers.length; i++) {
                System.out.println(allCustomers[i]);
            }
            
        } catch (Exception e) {
            System.out.println(e);
        }
        
        System.out.println();
        System.out.println();
        
        try {
            // testing getting a valid Customer
            System.out.println("BrokerDAOImplTest.main: retrieving valid customer Test Customer");
            customer = db.getCustomer("111-11-1111");
            System.out.println("BrokerDAOImplTest.main: " +  customer);
            
        } catch (Exception e) {
            System.out.println(e);
        }
        
        System.out.println();
        System.out.println();
        
        try {
            // testing getting an invalid customer
            System.out.println("BrokerDAOImplTest.main: retrieving invalid customer JUNK");
            customer = db.getCustomer("JUNK");
            System.out.println(customer);
        } catch (Exception e) {
            System.out.println(e);
        }
        
        System.out.println();
        System.out.println();
        
        try {
            
            // testing updating a valid customer
            System.out.println("BrokerDAOImplTest.main: retrieving exisiting customer test customer ");
            customer = db.getCustomer("111-11-1111");
            customer.setAddr("3333 Easy Street, East Beach AZ");
            
            db.changeCustomerInfo(customer);
            
        } catch (Exception e) {
            System.out.println(e);
        }
        
        System.out.println();
        System.out.println();
        
        try {
            
            // inserting a new customer record
            System.out.println("BrokerDAOImplTest.main:  inserting a new customer");
            customer = new Customer("111-11-1112","New Customer","2112 Easy Street, South Beach AZ");
            
            db.createCustomer(customer);
            
        } catch (Exception e) {
            System.out.println("BrokerDAOImplTest.main:  exception");
            System.out.println(e);
            System.out.println("BrokerDAOImplTest.main:  inserting will fail if 'New Customer' already in DB");
        }
        
        System.out.println();
        System.out.println();
        
        try {
            
            // deleting previously inserted new customer record
            System.out.println("BrokerDAOImplTest.main:  deleting new customer");
            customer = new Customer("111-11-1112","New Customer","2112 Easy Street, South Beach AZ");
            
            db.removeCustomer(customer);
            
        } catch (Exception e) {
            System.out.println("BrokerDAOImplTest.main:  exception");
            System.out.println(e);
        }
    }
}